<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <div id="app">
        <button v-on:click="addCount">{{ count }}</button>

        <button v-on:click="changeAge">change person age {{person.age}} </button>
        <button v-on:click="changePerson">change person {{person.age}} -- {{person.name}} </button>
        <button v-on:click="changeHeight">changeHeight {{person.height}} </button>
    </div>


    <!-- 引入vue -->
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
        const { createApp, ref, reactive, toRefs, watch } = Vue;
        // 创建Vue实例
        const app = createApp({
            setup() {
                const count = ref(0)
                const addCount = () => {
                    count.value++
                }

                let person = reactive({
                    name: '张三',
                    age: 18,
                    height: 180
                })
                let person2 = reactive({
                    name: '李四',
                    age: 20
                })

                const changeAge = () => {
                    person.age++
                }
                const changePerson = () => {
                    // person = { name: '李四', age: 20 }
                    person = person2
                    console.log("change person==>", person);

                }
                const changeHeight = () => {
                    person.height++
                }

                // watch(count, (newVal, oldVal) => {
                //     console.log("count change");
                //     console.log(newVal, oldVal);
                // })
                // wathc 只能监听到reactive属性的变化，不能监听到整个reactive对象修改
                // watch(person, (newVal) => {
                //     console.log(newVal);
                // })

                // watch(() => person.age, (newVal, oldVal) => {
                //     console.log(newVal, oldVal);
                // })

                watch([count, person2, () => person.age], (newVal, oldVal) => {
                    console.log(newVal, oldVal);
                })




                return {
                    count,
                    person,
                    addCount,
                    changeAge,
                    changePerson,
                    changeHeight
                }
            }
        })
        // 挂载到dom
        app.mount('#app')
    </script>
</body>

</html>